<?php
namespace Robot\Controller;
class MainController extends AdminbaseController {
	
	function _initialize() {
	}
    public function index(){
        $map["r.status"] = C("ROUND_STATUS.WAITING");

        $map["c.is_robot"] = C("DEFAULT_YN.NO");
        $map["o.status"] = C("ORDER_STATUS.WAITING_OPEN");
        $normalMoney = D("Round")->alias("r")
            ->join("left join __ORDER__ o on o.round_id = r.round_id")
            ->join("left join __CUSTOMER__ c on c.customer_id = o.customer_id")
            ->where($map)
            ->sum("o.number");

        $map["c.is_robot"] = C("DEFAULT_YN.NO");
        $normalCount = D("GroupMember")->alias("gm")
            ->join("left join __GROUP__ g on g.group_id = gm.group_id")
            ->join("left join __ROUND__ r on r.round_id = g.round_id")
            ->join("left join __ORDER__ o on o.group_id = g.group_id")
            ->join("left join __CUSTOMER__ c on c.customer_id = gm.customer_id")
            ->where($map)
            ->count("distinct(gm.member_id)");

        $map["c.is_robot"] = C("DEFAULT_YN.YES");
        $fakeMoney = D("Round")->alias("r")
            ->join("left join __ORDER__ o on o.round_id = r.round_id")
            ->join("left join __CUSTOMER__ c on c.customer_id = o.customer_id")
            ->where($map)
            ->sum("o.number");

        $fakeCount = D("GroupMember")->alias("gm")
            ->join("left join __GROUP__ g on g.group_id = gm.group_id")
            ->join("left join __ROUND__ r on r.round_id = g.round_id")
            ->join("left join __ORDER__ o on o.group_id = g.group_id")
            ->join("left join __CUSTOMER__ c on c.customer_id = gm.customer_id")
            ->where($map)
            ->count("distinct(gm.member_id)");

        $this->assign("normalMoney", isNullOrEmpty($normalMoney) ? 0 : $normalMoney);
        $this->assign("normalCount", $normalCount);
        $this->assign("fakeMoney", isNullOrEmpty($fakeMoney) ? 0 : $fakeMoney);
        $this->assign("fakeCount", $fakeCount);

        $this->display();
    }
}